//属性相关的API
import request from "../../../utils/request.ts";
import type {T_Attr, T_CategoryResponseData} from "./type.ts";
import {T_AttrResponseData} from "./type.ts";


enum API {
    //获取一级分类的地址
    C1_URL = "/admin/product/getCategory1",
    //获取二级分类的地址
    C2_URL = "/admin/product/getCategory2/",
    //获取三级分类的地址
    C3_URL = "/admin/product/getCategory3/",
    //获取确定1、2、3级下的属性值
    ATTR_URL = "/admin/product/attrInfoList/",
    //添加/修改属性的接口
    ADDORUPDATEATTR_URL = "/admin/product/saveAttrInfo",
    //删除请求
    DELETEATTR_URL = "/admin/product/deleteAttr/"
}

//获取一级分类的接口方法
export const reqC1 = () => request.get<any, T_CategoryResponseData>(API.C1_URL);

//获取二级分类的接口方法
export const reqC2 = (category1Id: number) => request.get<any, T_CategoryResponseData>(API.C2_URL + category1Id);

//获取三级分类的接口方法
export const reqC3 = (category2Id: number) => request.get<any, T_CategoryResponseData>(API.C3_URL + category2Id);

//获取分类下已有属性与属性值
export const reqGetAttrs = (c1: number, c2: number, c3: number) => request.get<any, T_AttrResponseData>(API.ATTR_URL + `${c1}/${c2}/${c3}`);

//新增/修改属性方法
export const reqAddOrUpdateAttr = (data: T_Attr) => request.post<any, any>(API.ADDORUPDATEATTR_URL, data)

//删除属性方法
export const reqRemoveAttr = (attrId: number) => request.delete<any, any>(API.DELETEATTR_URL + attrId);
